#pragma once

#include "MWTString.h"

namespace Myway
{
	enum OPEN_MODE
	{
		OM_READ						= 1,
		OM_WRITE					= 2,
		OM_READ_WRITE				= 3,
		OM_APPEND					= 4,
		OM_READ_WRITE_APPEND		= 5,

		OM_READ_BINARY              = 6,
		OM_WRITE_BINARY  			= 7,
		OM_READ_WRITE_BINARY  		= 8,
		OM_APPEND_BINARY  			= 9,
		OM_READ_WRITE_APPEND_BINARY = 10,
	};

	class MW_ENTRY File : public AllocObj
	{
	public:
		File();
		~File();

		bool			Open(const char * file, OPEN_MODE mode = OM_WRITE_BINARY);
		void			Close();
		bool			IsOpen();
		bool			Skip(int offset);
		bool			Seek(int pos);
		int			    Position();
		int			    Size();
		//int          Length();
		void            Flush();
		bool            eof();
		const TString128 &	FileName();

		int Write(const void * data, int esize, int count = 1);
		int Read(void * data, int esize, int count = 1);

	

	private:
		File(const File & file);
		File & operator =(const File & file);
		bool operator ==(const File & file);

	public:
		static const char ENDL;

	private:
		FILE *		mHandle;
		OPEN_MODE	mMode;
		TString128  mFile;
		bool        mEof;
	};

	class MW_ENTRY FileHelper
	{
	public:
		static TString128 GetExternName(const TString128 & file);
		static TString128 GetFileDir(const TString128 & file);
		static TString128 GetBaseName(const TString128 & file);
		static TString128 RemoveExternName(const TString128 & file);

		static bool Exist(const TString128 & file);
	};


} // end namespace Myway